import { constantRoutes } from '@/router'
import {asyncRoutes} from '@/router/asyncRoutes'

const state = {
  Routes:[],
  //默认现实
  asyncRoutes:[]
//  总的
}

const mutations = {
 SET_ASYNC_ROUTES(state,arr){
   state.Routes = constantRoutes
   state.asyncRoutes = state.Routes.concat(arr)
 },
 REST_ASYNC_ROUTES(state){
   state.Routes = []
   state.asyncRoutes = []
 }
}

const actions = {
  getAsyncRoutes({commit},userInfo){
    return new Promise(async (resolve, reject) => {
      const arr = asyncRoutes.filter(item=> item.meta.permission.indexOf(userInfo.url)!==-1 )
      commit('SET_ASYNC_ROUTES',arr)
      resolve()
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

